#!/usr/bin/env python
# -*- encoding: UTF-8 -*-
from __future__ import print_function

from flask import render_template, session, \
    request, redirect,url_for

from . import Nao
from . import main

#================= Nao 控制 ===============
@main.route('/nao/<name>', methods=['GET', 'POST'])
def nao_control(name):
    page_title = u"控制 Nao: " + name
    nao = Nao.get_by_name(name)
    id = nao.id
    urls = [
        {
            "url": "http://" + nao.IP,
            "text": u"%s 机器人网页" % name
        }
    ]
    btns = [
        {
            "id": "closeAutonomous",
            "name": u"关闭自主生活",
            "api": url_for("api.autonomous",nao_id=id,state="disabled")
        },
        {
            "id": "wakeUp",
            "name": u"唤醒",
            "api": url_for("api.wake_up",nao_id=id)
        },
        {
            "id": "rest",
            "name": u"放松",
            "api": url_for("api.rest",nao_id=id)
        },
        {
            "id": "StandZero",
            "name": u"零姿态",
            "api": url_for("api.go_to_posture",nao_id=id,postureName="StandZero")
        },
        {
            "id": "Stand",
            "name": u"站立",
            "api": url_for("api.go_to_posture",nao_id=id,postureName="Stand")
        },
        {
            "id": "Sit",
            "name": u"坐下",
            "api": url_for("api.go_to_posture",nao_id=id,postureName="Sit")
        },
        {
            "id": "closeLEDs",
            "name": u"关闭LED",
            "api": url_for("api.led",nao_id=id,option="off")
        },
        {
            "id": "openLEDs",
            "name": u"打开LED",
            "api": url_for("api.led",nao_id=id,option="on")
        },
        {
            "id": "openRHend",
            "name": u"打开右手",
            "api": url_for("api.hand",nao_id=id,option="open",handName="RHand")
        },
        {
            "id": "openLHend",
            "name": u"打开左手",
            "api": url_for("api.hand",nao_id=id,option="open",handName="LHand")
        },
        {
            "id": "closeRHend",
            "name": u"关闭右手",
            "api": url_for("api.hand",nao_id=id,option="close",handName="RHand")
        },
        {
            "id": "closeLHend",
            "name": u"关闭左手",
            "api": url_for("api.hand",nao_id=id,option="close",handName="LHend")
        }
    ]
    return render_template('index.html',page_title=page_title,urls=urls,btns=btns)